//package cn.zc.service.impl;
//import cn.zc.entity.Dizhi;
//import cn.zc.entity.User;
//import cn.zc.mapper.LoginMapper;
//import cn.zc.mapper.StudentMapper;
//import cn.zc.result.Result;
//import cn.zc.service.LoginService;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Service;
//
//import java.time.LocalDateTime;
//import java.time.format.DateTimeFormatter;
//import java.util.List;
//import java.util.UUID;
//
//@Service
//public class LoginServiceImpl implements LoginService {
//
//    @Autowired
//    private LoginMapper loginMapper;
//    @Autowired
//    private StudentMapper studentMapper;
//    public Result login(User user,String uuid,String latitude,String longitude) {
//        User login = loginMapper.login(user);
//        if (login == null) {
//            return Result.error("用户名或密码错误");
//        } else {
//            if (login.getType()==1){
//                return Result.success(1);
//            }
//            else{
//
////                if(latitude==null || longitude==null){
////                    return Result.success(-2);
////                }else {
////                    if(login.getLatitude()==null || login.getLongitude()==null){
////                        studentMapper.setlocal(latitude,longitude,login.getId());
////                    }else {
////                        if(!(login.getLatitude().equals(latitude)&&login.getLongitude().equals(longitude))) {
////                            return Result.success(-3);
////                        }
////                    }
////                }
//                if (login.getUuid() == null||login.getUuid().equals("null")){
//                    //生成uuid
//                    String newuuid = UUID.randomUUID().toString();
//                    studentMapper.setuuid(login.getId(),newuuid);
//                    //向登录日志里增添数据
//                    // 获取当前日期和时间
//                    LocalDateTime now = LocalDateTime.now();
//                    // 格式化日期时间
//                    DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
//                    String formattedDateTime = now.format(formatter);
//                    loginMapper.insertLoginLog(user.getId(),formattedDateTime);
//                    return Result.success(newuuid);
//                }else {
//                    if(uuid==null){
////                        return Result.success(-1);
//                        return Result.success(0);
//                    }
//                    if(!uuid.equals(login.getUuid())){
////                        return Result.success(-1);
//                        return Result.success(0);
//                    }else {
//                        //向登录日志里增添数据
//                        // 获取当前日期和时间
//                        LocalDateTime now = LocalDateTime.now();
//                        // 格式化日期时间
//                        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
//                        String formattedDateTime = now.format(formatter);
//                        loginMapper.insertLoginLog(user.getId(),formattedDateTime);
//                        return Result.success(0);
//                    }
//                }
//            }
//        }
//    }
//}
package cn.zc.service.impl;
import cn.zc.entity.Dizhi;
import cn.zc.entity.User;
import cn.zc.mapper.LoginMapper;
import cn.zc.mapper.StudentMapper;
import cn.zc.result.Result;
import cn.zc.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.UUID;

@Service
public class LoginServiceImpl implements LoginService {

    @Autowired
    private LoginMapper loginMapper;
    @Autowired
    private StudentMapper studentMapper;
    public int login(User user,String uuid,String latitude,String longitude) {
        User login = loginMapper.login(user);
        if (login == null) {
            return -1;
        } else {
            return login.getType();
            }
        }
    }
